<script setup lang='ts'>
import { ElPagination } from 'element-plus'
import { toRefs } from 'vue'

const props = withDefaults(defineProps<{
    data?: any
    draggable?: boolean
    total: any
}>(), {
    data: () => [],
    draggable: true,
})

const pageInfo = defineModel<any>('pageinfo', { required: true })
const emits = defineEmits(['doSort', 'pageChange'])
const { data, total } = toRefs(props)

function handleSizeChange(val: any) {
    console.log('size', val)
    pageChange()
}
function handleCurrentChange(val: any) {
    console.log('page', val)
    pageChange()
}

function pageChange() {
    emits('pageChange', { ...pageInfo.value })
}

function view(videoUrl = '') {
    if (videoUrl)
        window.open(videoUrl, '_block')
}

</script>

<template>
    <template v-if="data.length">
        <div v-for="(item, index) in data"
             :key="index"
             class="video-list"
        >
            <div class="left-content">
                <img v-if="item.videoCoverUrl"
                     :src="item.videoCoverUrl"
                     alt=""
                     @click="view(item.videoUrl)"
                >
                <img v-else
                     src="@/assets/images/default/video_cover.png"
                     alt=""
                     @click="view(item.videoUrl)"
                >

                <div class="content-desc">
                    <p style="font-weight: 600;line-height: 30px;">
                        {{ item.videoTitle }}
                    </p>

                    <p style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">
                        {{ item.titleDescription }}
                    </p>

                    <div class="flex" style="height:30px;line-height:30px;">
                        <p class="mr20" v-if="item.videoLabel" style="display:flex;align-items:center;">标签：<el-tag type="success">{{ item.videoLabel }}</el-tag></p>
                        <p v-if="item.orderFlag">排序：<el-tag type="info">{{ item.orderFlag }}</el-tag></p>
                    </div>
                    
                    <p>上传时间：{{ item.createTime }}</p>
                </div>
            </div>

            <div class="right-content">
                <slot name="action"
                      :index="index"
                      :row="item"
                />
            </div>
        </div>
    </template>

    <div v-else
         style="text-align: center;"
    >
        暂无数据
    </div>

    <ElPagination v-model:current-page="pageInfo.page"
                  v-model:page-size="pageInfo.size"
                  background
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="total"
                  flex
                  mt-20
                  justify-end
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
    />
</template>

<style lang="less" scoped>
.video-list {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #eef0f3;
    padding-bottom: 20px;
    margin-bottom: 20px;

    .left-content {
        display: flex;

        img {
            width: 176px;
            height: 117px;
            border: 1px solid rgb(0 0 0 / 5%);
            border-radius: 12px;
            cursor: pointer;
        }

        .content-desc {
            width: 500px;
            margin-left: 15px;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }
    }

    .right-content {
        display: flex;
        align-items: center;
    }
}
</style>
